using System.Reflection;
using System.Configuration;
using YouHP.ICacheDependency;

namespace YouHP.CacheDependencyFactory
{
    public static class DependencyAccess
    {
        /// <summary>
        /// Method to create an instance of Category dependency implementation
        /// </summary>
        /// <returns>Category Dependency Implementation</returns>
        public static IYouHPCacheDependency CreateTreatmentDependency()
        {
            return LoadInstance("Treatment");
        }

        /// <summary>
        /// Common method to load dependency class from information provided from configuration file 
        /// </summary>
        /// <param name="className">Type of dependency</param>
        /// <returns>Concrete Dependency Implementation instance</returns>
        private static IYouHPCacheDependency LoadInstance(string className)
        {

            string path = ConfigurationManager.AppSettings["CacheDependencyAssembly"];
            string fullyQualifiedClass = path + "." + className;

            // Using the evidence given in the config file load the appropriate assembly and class
            return (IYouHPCacheDependency)Assembly.Load(path).CreateInstance(fullyQualifiedClass);
        }
    }
}